using System;

namespace WebAndLoadTestPluginsAndRules.Common
{
    public class FilterFactory : IFilterFactory
    {
        public Filter GetFilter(string filter, FilterMethod filterMethod, bool ignoreCase)
        {
            switch (filterMethod)
            {
                case FilterMethod.StartsWith:
                    return new StartsWithFilter(filter, ignoreCase);
                case FilterMethod.ExactMatch:
                    return new ExactMatchFilter(filter, ignoreCase);
                case FilterMethod.Regex:
                    return new RegexFilter(filter, ignoreCase);

            }
            throw new ArgumentOutOfRangeException("filterMethod");
        }

        private class AlwaysTrueFilter : Filter
        {
            public override bool Matches(string value)
            {
                return true;
            }
        }


        private readonly static Filter _alwaysTrue = new AlwaysTrueFilter();
        public static Filter AlwaysTrue
        {
            get
            {
                return _alwaysTrue;
            }
        }
    }
}